using System.Collections.Generic;
using UnityEngine;

public class MobWayPoint : MonoBehaviour
{
	public float radius = 5f;

	public List<MobWayPoint> nextPoints = new List<MobWayPoint>();

	public List<MobWayPointCahedWays> wayPoints = new List<MobWayPointCahedWays>();

	public List<Vector3> cashedPoints = new List<Vector3>();

	public List<Vector3> CashRandomPoints(int n)
	{
		cashedPoints = new List<Vector3>(n);
		wayPoints = new List<MobWayPointCahedWays>();
		NavMeshPath path = new NavMeshPath();
		for (int i = 0; i < n; i++)
		{
			Vector3 vector = new Vector3(base.transform.position.x + Random.Range(0f, radius), base.transform.position.y, base.transform.position.z + Random.Range(0f, radius));
			RaycastHit hitInfo;
			if (Physics.Raycast(vector + Vector3.up * 3f, Vector3.down, out hitInfo, 1000f) && NavMesh.CalculatePath(hitInfo.point, base.transform.position, 11111111, path))
			{
				vector = hitInfo.point;
			}
			cashedPoints.Add(vector);
		}
		return cashedPoints;
	}

	public virtual Vector3 GetDestanationPoint()
	{
		return cashedPoints[Random.Range(0, cashedPoints.Count)];
	}

	public List<MobWayPointCahedWays> GetRandomPathFromThisPoint(int n = 5)
	{
		List<MobWayPoint> mobWay = GetRandomPathFromThisPoint(n, null);
		List<MobWayPointCahedWays> list = new List<MobWayPointCahedWays>();
		for (int i = 0; i < mobWay.Count; i++)
		{
			if (i < mobWay.Count - 1)
			{
				MobWayPointCahedWays[] array = mobWay[i].wayPoints.FindAll((MobWayPointCahedWays x) => x.endMobWayPoint == mobWay[i + 1]).ToArray();
				if (array.Length > 0)
				{
					list.Add(array[Random.Range(0, array.Length)]);
				}
			}
		}
		return list;
	}

	public List<MobWayPoint> GetRandomPathFromThisPoint(int i, MobWayPoint lastPoint)
	{
		List<MobWayPoint> list = new List<MobWayPoint>(i);
		list.Add(this);
		if (i != 0)
		{
			i--;
			List<MobWayPoint> list2 = nextPoints.FindAll((MobWayPoint x) => x != lastPoint);
			if (list2.Count == 0)
			{
				list2.Add(lastPoint);
			}
			int index = Random.Range(0, list2.Count);
			list.AddRange(list2[index].GetRandomPathFromThisPoint(i, this));
		}
		return list;
	}
}
